package com.baoli.blzj.utils;

import com.baoli.blzj.bean.home.HomeMenuBean;
import com.baoli.blzj.bean.home.HomePagerAdvertBean;
import com.baoli.blzj.bean.home.HomeTotalListBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * 首页数据解析 by John on 17/7/2.
 */

public class HomeDataJieXiUtils {

    public static HomeDataJieXiUtils getInstance() {
        HomeDataJieXiUtils hd = new HomeDataJieXiUtils();
        return hd;
    }

    public List<HomePagerAdvertBean> getImgDatas(List<HomePagerAdvertBean> img_list, JSONArray imgArr) {
        HomePagerAdvertBean hBean;
        try {
            for (int i = 0; i < imgArr.length(); i++) {
                JSONObject imgObj = imgArr.getJSONObject(i);
                hBean = new HomePagerAdvertBean();
                hBean.setImg_on(imgObj.getString("img_on"));
                hBean.setImg_url(imgObj.getString("img_url"));
                img_list.add(hBean);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return img_list;
    }

    public List<HomeMenuBean> getMenuDatas(List<HomeMenuBean> menuList, JSONArray gnArr) {
        HomeMenuBean mBean;
        try {
            for (int i = 0; i < gnArr.length(); i++) {
                mBean = new HomeMenuBean();
                JSONObject gnObj = gnArr.getJSONObject(i);
                mBean.setFuc_img(gnObj.getString("fuc_img"));
                mBean.setFuc_type(gnObj.getString("fuc_type"));
                mBean.setFuc_url(gnObj.getString("fuc_url"));
                mBean.setFun_cid(gnObj.getString("fuc_id"));
                mBean.setFuc_classname(gnObj.getString("fuc_classname"));
                mBean.setFun_name(gnObj.getString("fuc_name"));
                mBean.setFuncType(gnObj.getString("funcType"));
                menuList.add(mBean);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return menuList;
    }

    public List<HomeTotalListBean> getTotalDatas(List<HomeTotalListBean> totalList, JSONArray arr) {
        HomeTotalListBean bean;
        try {
            for (int i = 0; i < arr.length(); i++) {
                bean = new HomeTotalListBean();
                JSONObject obj = arr.getJSONObject(i);
                bean.setStore_id(obj.getString("store_id"));
                bean.setStore_addr(obj.getString("store_addr"));
                bean.setStore_name(obj.getString("store_name"));
                bean.setStore_note(obj.getString("store_note"));
                bean.setLogo_img(obj.getString("logo_img"));
                bean.setStore_distance(obj.getString("store_distance"));
                bean.setIs_sc(obj.getString("isCollected"));
                totalList.add(bean);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return totalList;
    }
}
